package com.five.community.service.impl;

import com.five.community.bean.Mailbox;
import com.five.community.bean.Village;
import com.five.community.bean.vo.MailboxVo;
import com.five.community.bean.vo.RepairVo;
import com.five.community.mapper.MailboxMapper;
import com.five.community.service.MailboxService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class MailoxService implements MailboxService {

    @Autowired
    private MailboxMapper mailboxMapper;

    @Override
    public List<MailboxVo> selectAll() throws Exception {
        return mailboxMapper.selectAllF();
    }

    @Override
    public List<MailboxVo> selectByName(String name) throws Exception {
        return mailboxMapper.selectByNameF(name);
    }

    @Override
    public void delete(long id) throws Exception {
        mailboxMapper.delete(id);
    }

    @Override
    public void insert(Mailbox mailbox) throws Exception {
        mailboxMapper.insert(mailbox);
    }

    @Override
    public Mailbox selectById(long id) throws Exception {
        return mailboxMapper.selectById(id);
    }

    @Override
    public void update(Mailbox mailbox) throws Exception {
        mailboxMapper.update(mailbox);
    }

    @Override
    public PageInfo<MailboxVo> getPageInfo(int pageNum, int pageSize) throws Exception {
        //先初始化模型在查询信息顺序不能颠倒
        //初始化分页插件模型
        PageHelper.startPage(pageNum,pageSize);
        //查询所有信息获得列表集合
        List<MailboxVo> mailboxVos = mailboxMapper.selectAllF();
        //分页模型加入数据
        PageInfo<MailboxVo> pageInfo = new PageInfo<>(mailboxVos);
        //返回分页模型
        return pageInfo;
    }
}
